package com.honey.solr;

import com.honey.core.types.FullyQualifiedJavaType;

public class SolrFullyQualifiedJavaType extends FullyQualifiedJavaType {
	
	/** solr 类型*/
	private String solrType;
	
	/** solr trie 类型(优化数据类型) */
	private String solrTrieType;
	
	/** solr 原始类型 */	
	private String solrPrimitiveType;
	
	/** solr 排序类型 */	
	private String solrSortableType;
	
	//private boolean chineseAnalyzer;

	private boolean text;
	
	private boolean string;
	
	public SolrFullyQualifiedJavaType(boolean chineseAnalyzer, String solrtype) {
		super(solrtype);
		if( this.text ){
			this.solrSortableType = 
			this.solrPrimitiveType = 
			this.solrTrieType = 
			this.solrType =  chineseAnalyzer ? SolrConstant.SOLR_SCHEMA_GENERAL_FIELD_TYPE :SolrConstant.SOLR_SCHEMA_CHINESE_FIELD_TYPE;
		}
	}
	
	/* (non-Javadoc)
	 * @see com.honey.core.types.FullyQualifiedJavaType#parse(java.lang.String)
	 */
	@Override
	protected void parse(String fullTypeSpecification) {
		String lower =fullTypeSpecification.toLowerCase();
		if( lower.indexOf("int") >= 0 || lower.indexOf("integer") >= 0 || lower.indexOf("short") >= 0 ){
			fullTypeSpecification =  "int";
			this.solrType = "int";
			this.solrTrieType = "tint";
			this.solrPrimitiveType = "pint";
			this.solrSortableType = "sint";
			
		}else if( lower.indexOf("long") >= 0 ){
			fullTypeSpecification =  "long";
			this.solrType = "long";
			this.solrTrieType = "tlong";
			this.solrPrimitiveType = "plong";
			this.solrSortableType = "slong";
			
		}else if( lower.indexOf("string") >= 0 || lower.indexOf("char") >= 0){
			fullTypeSpecification = "String";
			this.solrType = "string";
			this.solrTrieType = "atring";
			this.solrPrimitiveType = "string";
			this.solrSortableType = "string";
			this.string = true;
		}else if( lower.indexOf("float") >= 0 ){
			fullTypeSpecification = "float";
			this.solrType = "float";
			this.solrTrieType = "tfloat";
			this.solrPrimitiveType = "pfloat";
			this.solrSortableType = "sfloat";
			
		}else if( lower.indexOf("double") >= 0 ){
			fullTypeSpecification = "double";
			this.solrType = "double";
			this.solrTrieType = "tdouble";
			this.solrPrimitiveType = "pdouble";
			this.solrSortableType = "sdouble";
			
		}else if( lower.indexOf("date") >= 0 ){
			fullTypeSpecification = "java.util.Date";
			this.solrType = "date";
			this.solrTrieType = "tdate";
			this.solrPrimitiveType = "pdate";
			this.solrSortableType = "pdate";
		
		}else if( lower.indexOf("byte") >= 0 ){
			fullTypeSpecification = "byte[]";
			this.solrType = "binary";
			this.solrTrieType = "binary";
			this.solrPrimitiveType = "binary";
			this.solrSortableType = "binary";
		}else if( lower.indexOf("text") >= 0 ){
			fullTypeSpecification = "String";
			this.text = true;
			this.string = true;
		}
		super.parse(fullTypeSpecification);
	}

	/**
	 * solr 支持基础类型
	 * @return the solrType
	 */
	public final String getSolrType() {
		return solrType;
	}

	/**
	 * solr 支持trie类型(优化类型)
	 * @return the solrTrieType
	 */
	public final String getSolrTrieType() {
		return solrTrieType;
	}

	/**
	 * solr 支持原始类型
	 * @return the solrPrimitiveType
	 */
	public final String getSolrPrimitiveType() {
		return solrPrimitiveType;
	}

	/**
	 * solr 支持排序类型
	 * @return the solrSortableType
	 */
	public final String getSolrSortableType() {
		return solrSortableType;
	}

	/**
	 * @return the text
	 */
	public final boolean isText() {
		return text;
	}

	/**
	 * @return the string
	 */
	public final boolean isString() {
		return string;
	}
}
